<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends MY_Controller {
  var $captcha_url;
  function __construct() {
    parent::__construct();
    $this->captcha_url = base_url().'captcha';
  }

  function index() {
    $tips = $this->check() ? '' : '请输入帐号和密码';
    $this->load->helper('captcha');
    $vals = array(
      'word' => 9527,
      'img_path' => './captcha/',
      'img_url' => $this->captcha_url.'/',
      'img_width' => 50,
      'img_height' => 20,
      'expiration' => 7200
    );
    $cap = create_captcha($vals, $this->captcha_url);
    $data = array(
      'images_url' => $this->images_url,
      'css_images_url' => $this->css_images_url,
      'captcha' => $cap['image'],
      'tips' => $tips,
    );
    $this->load->view('login', $data);
  }

  function check() {
    if (empty($_POST['name']) || empty($_POST['password'])) {
      return false;
    }
    $query = $this->db->query('select * from cms_user where name = ? and password = ?', array($_POST['name'], $_POST['password']));
    if (empty($query)) return false;
    $this->session->set_userdata(array('name' => $_POST['name']));
    //$_SESSION['name'] = $_POST['name'];
    redirect('admin/index');
    

    //redirect('admin/aa');
  }
}


// END Login class

/* End of file Login.php */
/* Location: ./application/controllers/admin/Login.php */